<template>
  <div class="home">
    <ul>
      <li
        v-for="i in 10"
        :key="i"
        @click="change(i)"
        :class="flag == i ? active : ''"
      >
        <!-- :class="{
          bg: flag == i && flag % 2 == 0,
          bg2: flag == i && flag % 2 != 0,
        }" -->
        {{ i }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: -1,
      active: "bg",
    };
  },
  methods: {
    change(i) {
      this.flag = i;
      if (i % 2 == 0) {
        this.active = "bg";
      } else {
        this.active = "bg2";
      }
    },
  },
};
</script>
<style lang="scss">
.bg {
  background: chocolate;
}
.bg2 {
  background: cornflowerblue;
}
</style>
